package good

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"homepage_srv/homepageclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodCreateLogic {
	return &GoodCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 商品添加
func (l *GoodCreateLogic) GoodCreate(req *types.GoodCreateRequest) (resp *types.Response, err error) {
	good, err := l.svcCtx.HomepageGrpc.GoodCreate(l.ctx, &homepageclient.GoodCreateRequest{
		BrandId:       uint64(req.BrandId),
		MainImage:     req.MainImage,
		SliderImageId: uint64(req.SliderImageId),
		StoreName:     req.StoreName,
		StoreInfo:     req.StoreInfo,
		CateId:        uint64(req.CateId),
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}

	return respons.Success(good), nil
}
